<%namespace name="admin_include" file="/admin/base/include.html" />
<%inherit file="/front/base/businessbase.html"/>
<%def name="script()">
${admin_include.validationEngine()}
${admin_include.ueditor()}
${admin_include.jqueryUI()}
</%def>
<%def name="center()">
<div class="row">
    <h3 class="lit page-header no-margin" style="margin-bottom:10px;">优惠券发布</h3>
    %if info:
    <div class="alert alert-success"><strong>${info}</strong></div>
    %endif
    <form class="form-horizontal" id="dataform" action="/ajaxValidateSubmit" method="post" enctype="multipart/form-data">
        <fieldset>
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td colspan="2">
                        <div class="control-group">
                        <label class="control-label control-label-small">名称</label>
                            <div class="controls controls-small">
                                <input name="name" type="text" value="${coupon and coupon.name or ''}" class="input-large validate[required, maxSize[20]]"/>
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="control-group">
                        <label class="control-label control-label-small">类别</label>
                            <div class="controls controls-small">
                                <select name="coupontype" class="input-medium validate[required]" id="coupontype">
                                <option value="">--请选择--</option>
                                %if coupon:
                                ${h.getoptions('coupontype', str(coupon.coupontype))|n}
                                %else:
                                ${h.getoptions('coupontype')|n}
                                %endif
                                </select>
                            </div>
                        </div>
                    </td>
                    <td>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="control-group">
                        <label class="control-label control-label-small">有效期</label>
                            <div class="controls controls-row controls-small" id="div-datepicker">
                                <input id="startdate" name="startdate" type="text" value="${coupon and h.date(coupon.startdate) or ''}" class="input-medium validate[required, custom[date]]"/> -- <input id="enddate" name="enddate" type="text" value="${coupon and h.date(coupon.enddate) or ''}" class="input-medium validate[required, custom[date]]"/>
                            </div>
                        </div> 
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <div class="control-group">
                        <label class="control-label control-label-small">数量</label>
                            <div class="controls controls-small">
                                <input name="number" type="text" value="${coupon and coupon.number or ''}" class="input-medium validate[custom[integer]]"/>
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <div class="control-group">
                        <label class="control-label control-label-small">规则</label>
                            <div class="controls controls-small">
                                <input name="rule" type="text" value="${coupon and coupon.rule or ''}" class="input-small"/>
                                <span class="help-block">5/50(满50减5)</span>
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <div class="control-group">
                        <label class="control-label control-label-small">图片</label>
                            <div class="controls controls-small">
                                <input name="picture" type="file"/>
                                <span class="help-block">请上传260*180大小的图片</span>
                                %if coupon and coupon.picture:
                                <span class="help-block"><img src="${coupon.picture}" class="img-polaroid"/></span>
                                %endif
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <div class="control-group">
                        <label class="control-label control-label-small">简单描述</label>
                            <div class="controls controls-small">
                                <textarea id="shortdetail" name="shortdetail">${coupon and coupon.shortdetail or ''}</textarea>
                                <span class="help-block">会显示到首页或者优惠券列表中,突出广告效果，不要太长</span>
                                %if coupon and coupon.picture:
                                <span class="help-block"><img src="${coupon.picture}" class="img-polaroid"/></span>
                                %endif
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="control-group">
                        <label class="control-label control-label-small">详细</label>
                            <div class="controls controls-small">
                                    <textarea id="detail" name="detail">${coupon and coupon.detail or ''}</textarea>
                                    <script type="text/javascript">
                                        var editor_a = new baidu.editor.ui.Editor({
                                                initialContent:'',
                                                minFrameHeight:150,
                                                });
                                        editor_a.render('detail');
                                    </script>
                            </div>
                        </div>
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td colspan="2">
                        <div class="form-actions">
                            %if coupon:
                            <input type="hidden" name="id" value="${coupon and coupon.id or ''}"/>
                            %endif
                            <input type="hidden" name="form.submitted" value="save"/>
                            <input type="hidden" name="action" id="action"/>
                            <button class="btn btn-info" type="submit" id="savedraft">保存草稿</button>
                            <button class="btn btn-primary" type="submit" id="publish">立即发布</button>
                        </div>
                    </td>
                </tr>

            </table>
        </fieldset>
    </form>
</div>
<script type="text/javascript">
function ajaxValidationCallback(status, form, json, options)
{
    if(status)
    {
        form.attr('action', '${request.url}');
        form.validationEngine('detach');
        form.submit();
    }
}
$(document).ready(function(){
    $('#dataform').validationEngine({
            ajaxFormValidation: true,
            onAjaxFormComplete: ajaxValidationCallback,
    })
    $("#startdate").datepicker({
        defaultDate: "+1d",
        changeMonth: true,
        minDate: +1,
        onClose: function(selectedDate) {
            $("#enddate").datepicker("option", "minDate", selectedDate);
        }
    });
    $("#enddate").datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        onClose: function(selectedDate) {
            $("#startdate").datepicker("option", "maxDate", selectedDate);
        }
    });
    $("#ui-datepicker-div").css('font-size','82.5%');
    
    $('#savedraft').click(function(){
        $('#action').val('savedraft')
    })
    $('#publish').click(function(){
        $('#action').val('publish')
    })

});
</script>
</%def>
